package cn.knightzz.service.impl;

import cn.knightzz.entity.SysPopulationType;
import cn.knightzz.mapper.SysPopulationTypeMapper;
import cn.knightzz.service.SysPopulationTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author knightzz
 * @since 2021-05-09
 */
@Service
public class SysPopulationTypeServiceImpl extends ServiceImpl<SysPopulationTypeMapper, SysPopulationType> implements SysPopulationTypeService {

    @Resource
    SysPopulationTypeMapper populationTypeMapper;

    /**
     * 添加人口信息类型
     *
     * @param populationType
     * @return
     */
    @Override
    public Boolean addPopulationType(SysPopulationType populationType) {

        try {
            return populationTypeMapper.insert(populationType) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 删除人口信息
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deletePopulationType(Long id) {
        try {
            return populationTypeMapper.deleteById(id) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 更新人口信息类型
     *
     * @param populationType
     * @return
     */
    @Override
    public Boolean updatePopulationType(SysPopulationType populationType) {
        try {
            return populationTypeMapper.updateById(populationType) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 获取所有的人口数据类型
     *
     * @return
     */
    @Override
    public List<SysPopulationType> getAllPopulationTypeList() {
        try {
            return populationTypeMapper.selectList(null);
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
}
